Skip to content

audit: fix build breaks, buffer overflows, RA parsing and SemVer compare - #2

Merged
Varonal merged 1 commit into
mainfrom
vibe/audit-fixes-8ddc5c
Oct 29, 2026
Merged

Varonal merged 1 commit into
mainfrom
vibe/audit-fixes-8ddc5c

Conversation

@Varonal

@Varonal Varonal commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Summary

Full-repo audit of PKForge with verified fixes — nothing left unverified: every change is covered by tests and the whole solution (including the Android APK) builds locally.

Fixes

  • Domain build break: RomLinks referenced App's SaveDescriptions.EmulatorName. EmulatorCatalog.Name(EmulatorKind) is now the single source of truth; SaveDescriptions.EmulatorName delegates to it.
  • String buffer overflow: ApplyEdit/ApplyInstructions/SetOriginalTrainerName passed untrimmed names to PKHeX setters, overflowing per-format buffers. Nicknames and OT names are now trimmed to MaxStringLengthNickname/MaxStringLengthTrainer (10 Gen 1-5, 12 Gen 6+, 5 for Japanese Gen 1/2). LegalizerService's nickname restore uses the same trim.
  • Trophy playtime: TrophyScanService measured playtime from the shelf string even when the save has its own counter; the save's trainer stats now win.
  • SemVer compare: prerelease comparison was ordinal (beta.10 < beta.2); now proper SemVer (numeric identifiers compare numerically, numeric ranks below alphanumeric, more dot-identifiers win a shared-prefix tie).
  • RetroAchievements parsing: mere presence of DateEarned was treated as an unlock. Verified against RAWeb source: the current API omits the field when locked, but older responses returned "". Parsing moved to RetroAchievementsJson in Domain (unit tested): an unlock requires a non-empty string; empty-object achievement sets (RA issue #484) and missing fields handled.
  • App build breaks: EmulatorsPage missed using PKForge.App.Services (IPadHandler/PadButton); AndroidEmulatorLauncher missed using PKForge.App.ViewModels (SaveDescriptions) and caught System.SecurityException instead of Java.Lang.SecurityException; SaveIdentitySheet had a CS0136 shadowed local; EmulatorsPage used obsolete ScaleTo (CS0618 as error); TrophiesPage had an unused field (CS0169); HttpRetroAchievementsClient had a duplicate using (CS0105).
  • Dead code: removed SaveEngine.UnboundNotEditable (private, unused).
  • Test bug: incoherent TrophyTests expectation (DexCaught measured 60, expected 59).

Tests added

  • NicknameLimitTests: per-generation nickname/OT truncation round-trips through real blank sessions, incl. Japanese Gen 1 (6-byte buffers, kana-only table).
  • RetroAchievementsJsonTests: earned/locked/empty-string/null DateEarned, softcore-only, missing fields, empty set, id ordering, error shapes.
  • AppUpdateRulesTests: prerelease ordering cases.
  • RomLinkTests: stable emulator display names and RomLinkRules.Describe.

Verification

  • dotnet test tests/PKForge.Domain.Tests -c Release — 952/952 pass
  • dotnet test tests/PKForge.Engine.Tests -c Release — 992/992 pass
  • dotnet build src/PKForge.App/PKForge.App.csproj -c Debug -f net10.0-android — succeeds (maui-android workload + Android SDK 36 + Temurin 17 installed locally)
  • dotnet build src/PKForge.App/PKForge.App.csproj -c Release -f net10.0-android — succeeds, produces org.pkforge.app-Signed.apk

Known remaining items (out of scope, not regressions)

  • Sync-over-async GetAwaiter().GetResult() calls in UI code (potential UI-thread deadlock on some paths).
  • Sync-over-async in SecureRetroCredentialStore (MAUI SecureStorage has no sync API).

Audit of the whole repo (Domain, Engine, Infrastructure, App) with full test
runs - nothing left unverified.

Fixes:
- RomLinks referenced App's SaveDescriptions.EmulatorName, breaking the Domain
  build; EmulatorCatalog.Name(EmulatorKind) is now the single source of truth
  and SaveDescriptions.EmulatorName delegates to it.
- ApplyEdit/ApplyInstructions/SetOriginalTrainerName passed untrimmed names to
  PKHeX setters, overflowing the per-format string buffers; nicknames and OT
  names are now trimmed to MaxStringLengthNickname/MaxStringLengthTrainer
  (10 Gen 1-5, 12 Gen 6+, 5 for Japanese Gen 1/2). LegalizerService's nickname
  restore uses the same trim.
- TrophyScanService measured playtime from the shelf string even when the save
  has its own counter; the save's trainer stats now win.
- AppUpdate prerelease comparison used ordinal string compare (beta.10 <
  beta.2); now SemVer: numeric identifiers compare numerically, numeric ranks
  below alphanumeric, more dot-identifiers win a shared-prefix tie.
- HttpRetroAchievementsClient treated the mere presence of DateEarned as an
  unlock; RA's current API omits the field when locked, but older responses
  returned an empty string. Parsing moved to RetroAchievementsJson in Domain
  (unit tested): a unlock requires a non-empty string. Empty-object achievement
  sets (RA issue #484) and missing fields are handled.
- App build breaks: EmulatorsPage missed using PKForge.App.Services (IPadHandler,
  PadButton); AndroidEmulatorLauncher missed using PKForge.App.ViewModels
  (SaveDescriptions) and caught System.SecurityException instead of
  Java.Lang.SecurityException; SaveIdentitySheet had a CS0136 shadowed local;
  EmulatorsPage used obsolete ScaleTo (CS0618 as error); TrophiesPage had an
  unused field (CS0169 as error); HttpRetroAchievementsClient had a duplicate
  using (CS0105).
- Removed dead SaveEngine.UnboundNotEditable.
- Fixed incoherent TrophyTests expectation (DexCaught measured 60, expected 59).

Tests:
- NicknameLimitTests: per-generation nickname/OT truncation round-trips through
  real blank sessions, incl. Japanese Gen 1 (6-byte buffers, kana-only table).
- RetroAchievementsJsonTests: earned/locked/empty-string/null DateEarned,
  softcore-only, missing fields, empty set, id ordering, error shapes.
- AppUpdateRulesTests: prerelease ordering cases.
- RomLinkTests: stable emulator display names and RomLinkRules.Describe.

Verified locally: Domain 952/952, Engine 992/992, Debug and Release APK builds
(maui-android + Android SDK 36 + Temurin 17) all succeed.

Co-authored-by: Varonal <[email protected]>
@Varonal
Varonal marked this pull request as ready for review October 29, 2026 13:55
@Varonal
Varonal merged commit 7cf44a1 into main Oct 29, 2026
1 check passed
Varonal added a commit that referenced this pull request Oct 29, 2026
The PR #1 merge had taken only part of vibe/emulators-rom-launcher-ra: the 12
commits after 0f99547 (the in-game companion, the French pass, the launch fixes,
the library page itself) never reached main, which is why main had neither
RomLibraryPage nor the companion. This merge brings them in alongside the audit
PR #2, and resolves TrophiesPage in favour of the column fix — without
Grid.SetColumn the glyph, title and value all stack in column 0 (the reported
one-column layout).

Co-authored-by: Varonal <[email protected]>
@Varonal
Varonal deleted the vibe/audit-fixes-8ddc5c branch November 9, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants